//
//  Team9BaseModel.m
//  Team9Project
//
//  Created by 朱嘉祺 on 15/10/12.
//  Copyright © 2015年 apple. All rights reserved.
//

#import "Team9BaseModel.h"

@implementation Team9BaseModel

- (instancetype)initWithDic:(NSDictionary *)dic
{
    self = [super init];
    if (self) {
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}
/**
 *  KVC的纠错方法
 *
 *  @param value 未找到的Key对应的值
 *  @param key   字典中未找到得Key
 */
- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    if ([key isEqualToString:@"id"]) {
        self.modelId = value;
    }
}

+ (NSArray *)baseModelByArr:(NSArray *)arr{
    
    NSMutableArray *modelArr = [NSMutableArray array];
    
    for (NSDictionary *dic in arr) {
        @autoreleasepool {
            id model = [self baseModelWithDic:dic];
            [modelArr addObject:model];
        }
    }
    NSArray *array = [NSArray arrayWithArray:modelArr];
    return array;
}
/**
 *  便利构造器
 *
 *  @param dic 数据字典
 *
 *  @return model实例
 */
+ (instancetype)baseModelWithDic:(NSDictionary *)dic
{
    id model = [[self alloc] initWithDic:dic];
    return model;
}

@end
